package com.example.park2301.message

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.example.lib_base.entity.MessageBeanItem
import com.example.lib_base.net.ApiService

class MessageDataSource(val apiService: ApiService):PagingSource<Int,MessageBeanItem>() {
    override fun getRefreshKey(state: PagingState<Int, MessageBeanItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MessageBeanItem> {
       try {
           val startPa = params.key ?: 1
           val message = apiService.getMessage("111122223333", 1)
           val nextPa =if (message.data.size==10) startPa+1 else null
           return LoadResult.Page(message.data,null,nextPa)
       }catch (e:Exception){
           return LoadResult.Error(e)
       }
    }
}